<template>
	<view class="realName-page">
		<navigation :navigationMsg="navigationMsg"></navigation>
		<u-empty v-if="isAuth" mode="permission" icon="http://cdn.uviewui.com/uview/empty/permission.png" text="已实名">
		</u-empty>
		<view class="main" v-else>
			<view class="tip">
				实名认证后不可更改,请认真填写
			</view>
			<view class="real-box">
				<view class="name">
					<view class="title">
						真实姓名
					</view>
					<u--input fontSize="34rpx" placeholder="本人真实姓名" v-model="nameInput" border="none"></u--input>
				</view>
				<view class="code">
					<view class="title">
						身份证号
					</view>
					<u--input maxlength="18" fontSize="34rpx" placeholder="本人身份证号" v-model="codeInput"
						border="none"></u--input>
				</view>
			</view>
			<view class="submit" @click="submit">
				认证
			</view>
		</view>
	</view>
</template>

<script>
	import {
		http
	} from '@/api/index.js'
	import navigation from '../../../../../components/navigation.vue';
	export default {
		data() {
			return {
				navigationMsg: {
					title: "实名认证"
				},
				nameInput: "",
				codeInput: "",
				isAuth: false
			};
		},
		components: {
			navigation
		},
		onShow() {
			this.getUserInfo()
		},
		methods: {
			getUserInfo() {
				http.post('/api/account/getUserInfo').then(res => {
					if (res.verify) {
						this.isAuth = true
					} else {
						this.isAuth = false
					}
				}).catch(err => {

				})
			},
			//认证
			submit() {
				if (this.nameInput == "") {
					uni.showToast({
						title: "请输入姓名",
						icon: "none",
						duration: 1500
					})
					return
				}
				if (this.codeInput == "") {
					uni.showToast({
						title: "请输入身份证号",
						icon: "none",
						duration: 1500
					})
					return
				}
				http.post('/api/account/verify', {
					real_name: this.nameInput,
					id_card: this.codeInput
				}).then(res => {
					setTimeout(() => {
						uni.navigateBack()
					}, 1000)
				}).catch(err => {})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.realName-page {
		width: 100%;
		height: 100vh;
		background-color: #f7f7f7;

		.main {
			width: 100%;
			height: calc(100% - 100rpx);
			position: relative;
			overflow: hidden;

			.tip {
				width: 90%;
				margin: auto;
				margin-top: 30rpx;
				font-size: 28rpx;
				color: #9c9c9c;
			}

			.real-box {
				width: 90%;
				height: 240rpx;
				background-color: white;
				margin: auto;
				margin-top: 30rpx;
				border-radius: 20rpx;

				.name {
					width: 90%;
					height: 50%;
					border-bottom: 1px solid #dddddd;
					margin: auto;
					display: flex;
					align-items: center;
					font-size: 34rpx;
					justify-content: space-between;

					.title {
						width: 170rpx;
						text-align: center;
						margin-right: 20rpx;
					}
				}

				.code {
					width: 90%;
					height: 50%;
					margin: auto;
					display: flex;
					align-items: center;
					font-size: 34rpx;
					justify-content: space-between;

					.title {
						width: 170rpx;
						text-align: center;
						margin-right: 20rpx;
					}
				}
			}

			.submit {
				width: 90%;
				height: 80rpx;
				background-color: black;
				font-size: 34rpx;
				color: white;
				text-align: center;
				line-height: 80rpx;
				border-radius: 50rpx;
				position: absolute;
				bottom: 30rpx;
				left: 5%;
			}
		}
	}
</style>